# -*- coding: utf-8 -*-
# @Author  : haomh
# @Time    : 2025/11/20 09:43
# @Function:

'''
将房子剩余面积的家具摆放到房子中
'''
from turtledemo.paint import switchupdown


# 家具类
class Furniture():
    def __init__(self, name, area):
        self.name = name
        self.area = area


# 房子类
class Home():
    def __init__(self, address, area):
        self.address = address
        self.area = area
        self.free_area = area
        self.furniture = []

    def __str__(self):
        return f'房⼦子坐落于{self.address}, 占地⾯面积{self.area}, 剩余⾯面积{self.free_area}, 家具有{self.furniture}'

    def add_furniture(self, item):
        # 容纳家具
        if self.free_area >= item.area:
            self.furniture.append(item.name)
            self.free_area -= item.area
        else:
            print('家具太大，剩余⾯积不足，⽆无法容纳')


bed = Furniture('双人床', 6)
jia1 = Home('北京', 1200)
print(jia1)

jia1.add_furniture(bed)
print(jia1)

sofa = Furniture('沙发', 10)
jia1.add_furniture(sofa)
print(jia1)

ball = Furniture('篮球场', 1500)
jia1.add_furniture(ball)
print(jia1)